const Bank = class {
  constructor(balance) {
    this.balance = [...balance];
    this.n = balance.length;
  }

  transfer(account1, account2, money) {
    if (
      account1 < 1 ||
      account1 > this.n ||
      account2 < 1 ||
      account2 > this.n
    ) {
      return false;
    }
    const idx1 = account1 - 1;
    const idx2 = account2 - 1;
    if (this.balance[idx1] < money) {
      return false;
    }
    this.balance[idx1] -= money;
    this.balance[idx2] += money;
    return true;
  }

  deposit(account, money) {
    if (account < 1 || account > this.n) {
      return false;
    }
    const idx = account - 1;
    this.balance[idx] += money;
    return true;
  }

  withdraw(account, money) {
    if (account < 1 || account > this.n) {
      return false;
    }
    const idx = account - 1;
    if (this.balance[idx] < money) {
      return false;
    }
    this.balance[idx] -= money;
    return true;
  }
};
